﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsTests
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private async void button1_Click(object sender, EventArgs e)
        {
            try
            {

                //Form2 form2 = null;
                User user = null;
                await Task.Factory.StartNew(() =>
                {
                    int i = 0;
                    int j = 100 / i;
                    //ggg = new String("ggh".ToArray());
                    //form2 = new Form2();
                    //form2.ShowDialog();
                    user = new User();
                    user.Name = "Test";
                });
                //Thread.Sleep(1000);//确保form2被实例化了
                                   //textBox1.Text = ggg;//会报跨线程访问的错误
                user.Name = "ggh";
                textBox1.Text=user.Name;

                //Task.Run(() =>
                //{
                //    this.Invoke(new Action(() =>
                //    {
                //        int i = 0;
                //        int j = 100 / i;
                //        textBox1.Text = j.ToString();
                //    }));
                //});
            }
            catch (Exception err)
            {

                throw err;
            }
            
        }
    }
}
